import 'package:flutter/material.dart';

class Widget_Listener_Page extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Listener"),
        ),
        body: Center(
            child: Listener(
              child: Container(
                width: 200,
                height: 200,
                color: Colors.orange,
              ),
              onPointerDown: (event) =>
                  debugPrint("onPointerDown:  " + event.toString()),
              onPointerMove: (event) =>
                  debugPrint("onPointerMove:  " + event.delta.toString()),
              onPointerUp: (event) =>
                  debugPrint("onPointerUp:  " + event.toString()),
              onPointerEnter: (event) =>
                  debugPrint("onPointerEnter:  " + event.toString()),
              onPointerExit: (event) =>
                  debugPrint("onPointerExit:  " + event.toString()),
              onPointerCancel: (event) =>
                  debugPrint("onPointerCancel:  " + event.toString()),
              onPointerSignal: (event) =>
                  debugPrint("onPointerSignal:  " + event.toString()),
            )
        ),
      ),
    );
  }
}

/**
 *    触摸事件
 *   const Listener({
    Key key,
    this.onPointerDown,//按下时触发
    this.onPointerMove,//移动时触发
    this.onPointerEnter,//进入时触发
    this.onPointerExit,//离开时触发
    this.onPointerHover,//
    this.onPointerUp,//抬起时触发
    this.onPointerCancel,//取消触摸时触发
    this.onPointerSignal,//

    //HitTestBehavior.deferToChild  只有有子 Widget 通过了 Hit-Test，才接收一系列的事件，接收区域也会被限制在该子 Widget 区域中。
    //HitTestBehavior.opaque  Widget能够通过Hit-Test接收事件，且能阻止在它之前的 Widget接收事件。 简单来说就是事件 不能透传。
    //HitTestBehavior.translucent   Widget能够通过 Hit-Test接收事件，且不会阻止它之前的 Widget接收事件。 简单来说就是事件 能透传。
    this.behavior = HitTestBehavior.deferToChild,
    Widget child,
    })
 */


/**
 * PointerEvent 是PointerDownEvent ，PointerMoveEvent等的父类，保存了一些事件信息
 *
 *  delta            指针移动期间，与上一次事件的移动距离
 *
 * position     当前坐标,相对于全局坐标
 * timeStamp
 * pointer      标示一次触摸id。重新触摸会分配新的值
 * kind         触摸事件的输入类型。是触摸，还是鼠标
 * buttons
 * down
 * pressureMin
 * size
 * radiusMajor
 * radiusMinor
 */
// I/flutter: onPointerDown:  PointerDownEvent#44e67(position: Offset(170.2, 454.9), timeStamp: 122:57:38.630000, pointer: 34, kind: touch, buttons: 1, down: true, pressureMin: 0.0, size: 0.1, radiusMajor: 4.7, radiusMinor: 4.7)
// I/flutter: onPointerMove:  PointerMoveEvent#8206f(position: Offset(170.2, 454.9), timeStamp: 122:57:38.638000, pointer: 34, kind: touch, buttons: 1, down: true, pressureMin: 0.0, size: 0.0, radiusMajor: 4.0, radiusMinor: 4.0)
// I/flutter: onPointerMove:  PointerMoveEvent#263bf(position: Offset(170.2, 454.9), timeStamp: 122:57:38.647000, pointer: 34, kind: touch, buttons: 1, down: true, pressureMin: 0.0, size: 0.0, radiusMajor: 3.6, radiusMinor: 3.6)
// I/flutter: onPointerMove:  PointerMoveEvent#d0296(position: Offset(170.2, 454.9), timeStamp: 122:57:38.655000, pointer: 34, kind: touch, buttons: 1, down: true, pressureMin: 0.0, size: 0.0, radiusMajor: 3.3, radiusMinor: 3.3)
// I/flutter: onPointerMove:  PointerMoveEvent#8270e(position: Offset(170.2, 454.9), timeStamp: 122:57:38.663000, pointer: 34, kind: touch, buttons: 1, down: true, pressureMin: 0.0, size: 0.0, radiusMajor: 2.9, radiusMinor: 2.9)
// I/flutter: onPointerMove:  PointerMoveEvent#545b7(position: Offset(170.2, 454.9), timeStamp: 122:57:38.671000, pointer: 34, kind: touch, buttons: 1, down: true, pressureMin: 0.0, size: 0.0, radiusMajor: 2.2, radiusMinor: 2.2)
// I/flutter: onPointerMove:  PointerMoveEvent#bc354(position: Offset(170.2, 454.9), timeStamp: 122:57:38.680000, pointer: 34, kind: touch, buttons: 1, down: true, pressureMin: 0.0, size: 0.0, radiusMajor: 2.5, radiusMinor: 2.5)
// I/flutter: onPointerUp:  PointerUpEvent#7bd6e(position: Offset(170.2, 454.9), timeStamp: 122:57:38.696000, pointer: 34, kind: touch, down: false, pressureMin: 0.0, size: 0.0, radiusMajor: 2.5, radiusMinor: 2.5)
